﻿using NLog;
using System;
using AyFrame.Dto;

namespace AyFrame.NSerialLog
{
    public class LogHelper
    {
        static readonly Logger _Logger = LogManager.GetCurrentClassLogger();

        public static void LogDb(SystemLogView log)
        {
            var li = new LogEventInfo(LogLevel.Trace, "", "");
            li.Properties["Id"] = log.Id;
            li.Properties["logData"] = log.LogData;
            li.Properties["method"] = log.Method;
            li.Properties["tableName"] = log.TableName;
            li.Properties["addTime"] = DateTime.Now;
            li.Properties["operUid"] = log.OperUid;
            li.Properties["LogType"] = log.OperUid;

            _Logger.Trace(li);
        }

        public static void LogInfo(string msg, string apiAddr = null)
        {
            if (string.IsNullOrWhiteSpace(apiAddr))
                _Logger.Info($"{msg}");
            else
                _Logger.Info($"{apiAddr}\r\n    {msg}");
        }

        public static void LogError(string msg, Exception ex)
        {
            _Logger.Error(ex, msg);
        }
    }
}
